﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace PDFWriter
{
    public class PDFArray : INode
    {
        private XmlDocument reader = new XmlDocument();

        public const string ARRAY = "Array";
        public const string ARRAY_ELEMENT = "ArrayElement";

        const string ARRAY_START = "[";
        const string ARRAY_END = "]\n";

        public PDFArray(string xmlDictionary)
        {
            reader.LoadXml(xmlDictionary);
        }

        public PDFObject GetPDFObject()
        {
            PDFObject pdfObject = new PDFObject() { Text = ProcessXML() };
            return pdfObject;
        }

        public string ProcessXML()
        {
          string resultString = null;
          if (reader.FirstChild.Name == ARRAY)
            {
                resultString = ARRAY_START;
                foreach (XmlNode node in reader.FirstChild.ChildNodes)
                {
                    if (node.Name == ARRAY_ELEMENT)
                    {
                        resultString += GetArrayElement(node);
                    }
                }
                resultString += ARRAY_END;
            }
            return resultString;
        }

        public string GetArrayElement(XmlNode arrayElement)
        {
            string currentElementString = "";
            currentElementString += arrayElement.InnerText;
            return currentElementString;
        }

        #region INode Members


        public List<PDFObject> GetPDFObjects()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
